import { put, call, takeEvery, all, fork } from 'redux-saga/effects';
import { LNR_GET_TABLE_DATA, lnrChangeTableLoading, lnrSetTableData } from './actions';
import { getListNotifyResultData } from '../api';
import { axios } from 'utils';


function* getTableData(action) {
    yield put(lnrChangeTableLoading(true));
    try{
        const res = yield call(getListNotifyResultData, action.params);
        if(Number(res.code) === 200) {
            // const { data } = res;
            // const obj = {
            //     data: data.records || [],
            //     pagination: {
            //         total: data.totalRecords,
            //         current: data.currentPage
            //     }
            // }
            const { data:content } = res;
            const obj = {
                data: content || [],
                pagination: {}
            }
            yield put(lnrSetTableData(obj));
        }
    } catch (e) {

    }
    yield put(lnrChangeTableLoading(false));
}

function* watchGetTableData() {
    yield takeEvery(LNR_GET_TABLE_DATA, getTableData);
}

export default function* root() {
    yield all([
        fork(watchGetTableData)
    ])
}
